package com.tattermedia.allthataudio.audio;

import hw.ats.news.R;
import hw.ats.news.activity.news.RecentAct;
import hw.ats.news.model.News;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.BaseAdapter;
import android.widget.Toast;

public class AudioPlayerDialogTool {
	
	public static void showPlayOrAddDialog(final Context context, final News entry) {
		new AlertDialog.Builder(context)
		.setTitle(R.string.playlist_act_name)
		.setMessage("")
		.setPositiveButton(R.string.audio_play, new DialogInterface.OnClickListener() {
		    public void onClick(final DialogInterface dialog, final int arg1) {
		    	
		    	AudioPlayerManager manager = AudioPlayerManager.getManager();
		    	
		    	manager.addToPlayList(entry);
		    	
		    	try {
					manager.playAudioFromUid(entry.uid);
					Toast.makeText(context, R.string.audio_now_start_play, Toast.LENGTH_SHORT).show();
				} catch (Exception e) {
					Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
				}
		    	
		    	
		    }
		})
		.setNegativeButton(R.string.audio_add, new DialogInterface.OnClickListener() {
		    public void onClick(final DialogInterface dialog, final int arg1) {
		    	
		    	boolean retValue = AudioPlayerManager.getManager().addToPlayList(entry);
		    	
		    	if (retValue) {
		    		Toast.makeText(context, R.string.audio_playlist_added, Toast.LENGTH_SHORT).show();
		    	} else {
		    		Toast.makeText(context, R.string.audio_playlist_already_exist, Toast.LENGTH_SHORT).show();
		    	}
		    	
		    }
		})
		.show();
	}
	
	public static void showPlayListRemoveItemDialog(final Context context, final PlayListItem item, final BaseAdapter baseAdapter) {
		
		new AlertDialog.Builder(context)
		.setTitle(R.string.playlist_act_name)
		.setMessage(R.string.audio_playlist_are_you_sure_remove)
		.setPositiveButton(R.string.common_yes, new DialogInterface.OnClickListener() {
		    public void onClick(final DialogInterface dialog, final int arg1) {
		    	
		    	AudioPlayerManager.getManager().removeFromPlayList(item);
		    	
		    	baseAdapter.notifyDataSetChanged();
		    	
		    	Toast.makeText(context, R.string.audio_playlist_deleted, Toast.LENGTH_SHORT).show();
		    }
		})
		.setNegativeButton(R.string.common_no, new DialogInterface.OnClickListener() {
		    public void onClick(final DialogInterface dialog, final int arg1) {

		    }
		})
		.show();
	}
}
